package com.smxy.hunzi.article.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smxy.hunzi.common.utils.PageUtils;
import com.smxy.hunzi.common.utils.Query;

import com.smxy.hunzi.article.dao.ModuleDao;
import com.smxy.hunzi.article.entity.ModuleEntity;
import com.smxy.hunzi.article.service.ModuleService;


@Service("moduleService")
public class ModuleServiceImpl extends ServiceImpl<ModuleDao, ModuleEntity> implements ModuleService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<ModuleEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            wrapper.like("id", key)
                    .or()
                    .like("module_name", key);
        }
        IPage<ModuleEntity> page = this.page(
                new Query<ModuleEntity>().getPage(params),
                wrapper
                .orderByDesc("sort")
        );

        return new PageUtils(page);
    }

}